home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11765 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: prairienet.org!wemccaug
  2. From: wemccaug@prairienet.org (Wendy E. McCaughrin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: friend functions and access to private variables...
  5. Date: 16 Mar 1996 02:20:08 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4id8go$12q@vixen.cso.uiuc.edu>
  8. References: <4hogra$gnn@nntp.ucs.ubc.ca> <4ho95g$hjq@ccshst05.cs.uoguelph.ca>
  9. Reply-To: wemccaug@prairienet.org (Wendy E. McCaughrin)
  10. NNTP-Posting-Host: firefly.prairienet.org
  11.  
  12.  
  13. In a previous article, jamesdf@unixg.ubc.ca (James Fairweather) says:
  14.  
  15. >>I'm dealing with two classes, where a member function of class A is declared as
  16. >>a friend function of class B.
  17. >
  18. >>Unfortunately this does not allow the friend function access to private variables in
  19. >>class B...what gives? Is it not legal to make such a declaration?
  20. >
  21. >Heh, you have it backwards.  To allow class A to access B's private
  22. >members, put friend class _A_; in B's header.
  23. >
  24. >    James
  25. >
  26. >
  27.  Mr. Fairweather says (in effect):
  28.  
  29.  class A { public: ...
  30.            void memfunc(); // is the member-function in question
  31.  
  32.  How could A's members invite themselves to be friends of B: class
  33.  B has to extend that invitation. All class A can do is declare some
  34.  other function or class to be a friend of it. So it is not legal
  35.  to make such a declaration.
  36.  
  37.  As to the first respondent, it did not appear that Mr. Fair-
  38.  weather wanted all of class A to have access to B's private part,
  39.  only one member function, so in class B's specification
  40.  you want to include something like: friend void A::memfunc().
  41.  
  42.  wem
  43.  
  44.